﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Krile.Common.Suggestor
{
    public partial class SuggestableTextBox : UserControl
    {
        internal SuggestableTextBoxCore TextCore
        {
            get { return this.textCore; }
        }

        public SuggestableTextBox()
        {
            InitializeComponent();
            textCore.LanguageOption = RichTextBoxLanguageOptions.AutoFont;
            textCore.TextChanged += new EventHandler(textCore_TextChanged);
            textCore.KeyDown += new KeyEventHandler(TextCore_KeyDown);
            textCore.PreviewKeyDown += new PreviewKeyDownEventHandler(textCore_PreviewKeyDown);
        }

        protected void RefreshOverflowColoring()
        {
            textCore.UpdateOverflowCheck();
        }

        #region Virtual implementations

        #region Events

        public new event PreviewKeyDownEventHandler PreviewKeyDown;
        void textCore_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
        {
            if (this.PreviewKeyDown != null)
                this.PreviewKeyDown(sender, e);
        }

        public new event KeyEventHandler KeyDown;
        void TextCore_KeyDown(object sender, KeyEventArgs e)
        {
            if (this.KeyDown != null)
                this.KeyDown(sender, e);
        }

        public new event EventHandler TextChanged;
        void textCore_TextChanged(object sender, EventArgs e)
        {
            if (this.TextChanged != null)
                TextChanged(sender, e);
        }

        #endregion

        #region Properties

        public override string Text
        {
            get { return textCore.Text; }
            set { textCore.Text = value; }
        }

        public int SelectionStart
        {
            get { return textCore.SelectionStart; }
            set{textCore.SelectionStart = value;}
        }

        public int SelectionLength
        {
            get { return textCore.SelectionLength; }
            set { textCore.SelectionLength = value; }
        }

        public string SelectedText
        {
            get { return textCore.SelectedText; }
            set { textCore.SelectedText = value; }
        }

        #endregion

        #region Methods

        public void Clear()
        {
            textCore.Clear();
        }

        public void ClearUndo()
        {
            textCore.ClearUndo();
        }

        public void SelectAll()
        {
            textCore.SelectAll();
        }


        #endregion

        #endregion

        #region Overridables

        public virtual int TextMaxLimitLength { get { return -1; } }

        public virtual char[] SuggestCandidates
        {
            get { return null; }
        }

        public virtual SuggestList GetList(char hitCandidate, int targetStart, Point showLocation)
        {
            return null;
        }

        #endregion
    }
}
